Improved variable init and bug fixes