Final debugging and code clean-up