Code cleanup, and following specs