Code organized and fixed a bug