Code cleanup, abstractions