Final working version (Not cleaned up yet)