Changed file structure, added more logic