Cleaned up code a little, still needs more work