fixed some issues; cleaned up code