Source code simplification and bug fixes