Cleaning code, made more efficent