Bug fixes and improved file structure