somewhat refactored - night