removing hacks and cleanning up code