bug fixes and cleanup for loading