bug fix
refactored a bit, got rid of global package